﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.BaseData
{
    public partial class AddClass : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("BJSJ");
            strPageUserType.Add("mana");

            tb.Style.Add("display", "none");
            if (!IsPostBack)
            {
                BindDDl();
            }
        }

        /// <summary>
        /// 年级绑定
        /// </summary>
        protected void BindDDl()
        {
            //ExtendBLL.SysSetting ES = new ExtendBLL.SysSetting();
            //int Year = ES.GetCurrentSetting().CurrentYear;
            //int S =int.Parse(ES.GetCurrentSetting().CurrentSemester.Value.ToString());
            //ddlClass.DataSource=Common.GradeHelper.GetCurrentGrade(Year,S,false);
            //ddlClass.DataBind();

            //从字典中取值，入学年份
            LabMS.BLL.Dictionary bDictionary = new LabMS.BLL.Dictionary();
            string str = "DClass='ruxuenianfen'";
            ddlClass.DataSource=bDictionary.GetModelList(str);
            ddlClass.DataTextField = "Name";
            ddlClass.DataValueField = "Code";
            ddlClass.DataBind();
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbClassNumber.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "班号不能为空！");
                tbClassNumber.Focus();
            }
            else if (string.IsNullOrEmpty(tbClassName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "班级名称不能为空！");
                tbClassName.Focus();
            }
            else if (string.IsNullOrEmpty(tbNum.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "班级人数不能为空！");
                tbNum.Focus();
            }
            else if (string.IsNullOrEmpty(tbClassMajor.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "所属专业不能为空！");
                tbClassMajor.Focus();
            }
            else
            {
                LabMS.Model.Class cclass = new LabMS.Model.Class();
                ExtendBLL.Class extendclass = new ExtendBLL.Class();

                if(extendclass.IsExistClass(tbClassNumber.Text.Trim())==1)
                {
                    Common.JShelper.JSAlert(this.Page,"","该班级编号已经存在！");
                    tbClassNumber.Text="";
                    tbClassNumber.Focus();
                }
                else
                {
                    cclass.Class_Professional =int.Parse(tb.Text.Trim());//专业
                    cclass.Class_Code = tbClassNumber.Text.Trim();//班级编号
                    cclass.Class_Name = tbClassName.Text.Trim();//班级名称
                    cclass.Class_Year = ddlClass.SelectedValue;//年级
                    cclass.Class_StudentNum =int.Parse(tbNum.Text.Trim());//人数
                    int a=extendclass.Add(cclass);
                    if (a > 0)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增成功！');window.opener.location.href=window.opener.location.href;self.close();</script>");
                    }
                    else
                    {
                        Common.JShelper.JSAlert(this.Page,"","新增失败！");
                    }
                }
            }
        }
    }
}
